home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / MAG04.ZIP / MAG04.TXT < prev   
Encoding:
Text File  |  1995-10-27  |  30.2 KB  |  757 lines

  1. Spellcaster presents:
  2.  
  3.  
  4. TTTTTTTTTT HH      HH EEEEEEEEEE    MM      MM    AAAA     GGGGGGGGG
  5.     TT     HH      HH EE            MMM    MMM   AA  AA   GG
  6.     TT     HH      HH EE            MM M  M MM  AA    AA  GG  
  7.     TT     HHHHHHHHHH EEEEEE        MM  MM  MM  AAAAAAAA  GG   
  8.     TT     HH      HH EE            MM      MM  AA    AA  GG    GGGG
  9.     TT     HH      HH EE            MM      MM  AA    AA  GG      GG
  10.     TT     HH      HH EEEEEEEEEE    MM      MM  AA    AA   GGGGGGGG
  11.  
  12.                                                         Issue 4
  13.                                                         25-10-95
  14.  
  15.  
  16.  
  17. ■ Index
  18.  
  19.         1. Introduction
  20.           1.1. About the magazine
  21.           1.2. About the author
  22.           1.3. Distribution
  23.           1.4. Contribuitions
  24.           1.5. Hellos and greets
  25.         2. Bikes and programs - What to they have in common ?
  26.           2.1. Introduction
  27.           2.2. The For cicle
  28.           2.3. The Repeat...Until...
  29.           2.4. While loop
  30.         3. Graphics, part 3 : Lines and circles
  31.           3.1. Lines
  32.           3.2. Circles
  33.         4. Hints and tips
  34.         5. Points of view
  35.         6. The adventures of Spellcaster, part 4
  36.  
  37. ■ Introduction
  38.  
  39.   ■ About the magazine
  40.  
  41.     Hello, everybody out there... Here it is: number four of 'The Mag', brought
  42.   to you, as usual, by Spellcaster, alias Diogo de Andrade.
  43.     As you may have noticed, this issue is very late, due to the beginning
  44.   of scholl... But, never the less, here it is.
  45.     This issue includes part III of my mode 13h tutorial, more begginers
  46.   teaching and a new regular, called 'Hints and tips', something like a bunch
  47.   of tricks I found out during my coding days. I want to put there tips for
  48.   everybody, from the begginner to the advanced programmer.
  49.     This magazine is dedicated to all the programmers and would-be programmers
  50.   out there, especially to those that (like me) can't access the Net easily to 
  51.   get valuable information, and to those who wish to learn how to program 
  52.   anything, from demos to games, passing through utilities and all sort of 
  53.   thing your mind can think of.
  54.  
  55.     Somobody told me that the magazine had things too complicated, like the
  56.   article on pointers and the ones about graphics. As I said before, these
  57.   aren't meant for the begginer, but for the more serious programmers. I must
  58.   catter for everybody. So, if any begginers are worried because they don't
  59.   understand shit, don't worry. Just continue to follow the begginers articles,
  60.   and I will tell you when you can go back to previous issues.
  61.  
  62.     When you read this magazine, I'll assume some things. First, I assume you
  63.   have Borland's Turbo Pascal, version 6 and upwards. I'll also think you have
  64.   a 80386 (or 386 for short; a 486 would be even better), a load of patience
  65.   and a sense of humor. This last is almost essencial, because I don't receive
  66.   any money for doing this, so I must have fun doing it. I will also take for
  67.   certain you have the 9th grade (or equivelent). Finally, I will assume that
  68.   you have the last issues of 'The Mag', and that you have grasped the concepts
  69.   I tried to transmit. If you don't have the issues, you can get them by mail,
  70.   writing to the adress shown below.
  71.  
  72.     As I stated above, this magazine will be made especially for those who don't
  73.   know where to get information, or want it all in the same place, and to those
  74.   who want to learn how to program, so I'll try to build knowledge, building up
  75.   your skills issue by issue. If you sometimes fail to grasp some concept, don't
  76.   despair; try to work it out.
  77.     That's what I did... Almost everything I know was learnt from painfull
  78.   experience. If you re-re-re-read the article, and still can't understand it,
  79.   just drop a line, by mail, or just plain forget it. Most of the things I 
  80.   try to teach here aren't linked to each other (unless I say so), so if you
  81.   don't understand something, skip it and go back to it some weeks later. It
  82.   should be clearer for you then. Likewise, if you see any terms or words you 
  83.   don't understand, follow the same measures as before.
  84.  
  85.     Ok, as I'm earing the Net gurus and other god-like creatures talking
  86.   already, I'm just going to explain why I use Pascal.
  87.   For starters, Pascal is a very good language, ideal for the beginner, like 
  88.   BASIC (yech!), but it's powerfull enough to make top-notch programms.
  89.   Also, I'll will be using assembly language in later issues, and Pascal makes
  90.   it so EASY to use. 
  91.   Finally, if you don't like my choice of language, you can stop whining. The
  92.   teory behind each article is very simple, and common with any of the main
  93.   languages (C, C++, Assembly - Yes, that's true... BASIC isn't a decent
  94.   language).
  95.  
  96.     Just one last thing... The final part of the magazine is a little story
  97.   made up by my distorted mind. It's just a little humor I like to write, and
  98.   it hasn't got nothing to do with programming (well, it has a little), but, 
  99.   as I said before, I just like to write it.
  100.  
  101.   ■ About the author
  102.  
  103.     Ok, so I'm a little egocentric, but tell me... If you had the trouble of 
  104.   writing hundreds of lines, wouldn't you like someone to know you, even by 
  105.   name ?
  106.  
  107.     My name is Diogo de Andrade, alias Spellcaster, and I'm the creator, 
  108.   editor and writer of this magazine. 
  109.     I live in a small town called Setúbal, just near Lisbon, the capital of
  110.   Portugal... If you don't know where it is, get an encyclopedia, and look for
  111.   Europe. Then, look for Spain. Next to it, there's Portugal, and Setúbal is in
  112.   the middle.
  113.  
  114.     I'm 18 years old, and I just made it in to the university (if you do want
  115.   to know, I'm in the Technical Institute of Lisbon, Portugal), so I'm not 
  116.   a God-Like creature, with dozens of years of practice (I only program by 
  117.   eight years now, and I started in a Spectrum, progressing later to an Amiga.
  118.   I only program in the PC for a year or so), with a mega-computer (I own a 
  119.   386SX, 16 Mhz), that wear glasses with lens that look like the bottom of a 
  120.   bottle (I use glasses, but only sometimes), that has his head bigger than a 
  121.   pumpkin (I have a normal sized head) and with an IQ of over 220 (mine is 
  122.   actually something like 180). I can program in C, C++, Pascal, Assembly 
  123.   and even BASIC (yech!).
  124.  
  125.     So, if I am a normal person, why do I spend time writing this ?
  126.   Well, because I have the insane urge to write thousands of words every now
  127.   and then, and while I'm at it, I may do something productive, like teaching
  128.   someone. I may be young, but I know a lot about computers (how humble I am;
  129.   I know, modesty isn't one of my qualities).
  130.  
  131.     Just one more thing, if you ever program anything, please send to me... I
  132.   would love to see some work you got, maybe I even could learn something with
  133.   it. Also, give me a greet in your program/game/demo... I love seeing my 
  134.   name.
  135.  
  136.   ■ Contributions
  137.  
  138.     I as I stated before, I'm not a God... I do make mistakes, and I don't 
  139.   have (always) the best way of doing things. So, if you think you've spotted
  140.   an error, or you have thought of a better way of doing things, let me know.
  141.   I'll be happy to receive anything, even if it is just mail saying 'Keep it 
  142.   up'. As all human beings, I need incentive.
  143.  
  144.     Also, if you do like to write, please do... Send in articles, they will be
  145.   welcome, and you will have the chance to see your names up in lights.
  146.     They can be about anything, for a review of a book or program that can
  147.   help a programmer, to a point of view or a moan.
  148.  
  149.     If anyone out there has a question or wants to see an article about 
  150.   something in particular, feel free to write... All letters will be answered,
  151.   provided you give me your address.
  152.  
  153.     I'm also trying to start a new demo/game/utility group, and I need all sort 
  154.   of people, from coders (sometimes, one isn't enough), musicians (I can 
  155.   compose, but I'm a bit limited), graphics artists (I can't draw nothing) and
  156.   spreaders... I mean, by a spreader, someone who spreads things, like this mag.
  157.   If you have a BBS and you want it to include this magazine, feel free to
  158.   write me...
  159.  
  160.     You can also contact me personally, if study on the IST (if you don't
  161.   know what the IST is, you don't study there). I'm the freshman with the 
  162.   black hair and dark-brown eyes... Yes, the one that is occupying one of
  163.   the X-terminals... I recommend you to contact me personally, if you can,
  164.   especially if you are a member of the opposite sex (I'm a man, for those
  165.   of you who are wondering).
  166.  
  167.     My adress is:
  168.                  Praceta Carlos Manito Torres, nº4/6ºC
  169.                  2900 Setúbal
  170.                  Portugal
  171.  
  172.     Email: dgan@rnl.ist.utl
  173.  
  174.  
  175.   ■ Hellos and greets
  176.  
  177.     I'll say hellos and thanks to all my friend, especially for those who put 
  178.   up with my constant whining (you know who you are).
  179.     Special greets go to Denthor from Asphyxia (for the excelent VGA trainers),
  180.   Draeden from VLA (for assembly tutorials), Joaquim Elder Guerreiro, alias
  181.   Dr.Shadow (Delta Team is still up), Alex "Darkfox" (thanks for letting me
  182.   use your BBS), Joäo Neves and Henrique Craveiro for sugestions, and all the
  183.   demo groups out there.
  184.     I also want to say hi to my idols (I know they don't read this, but...),
  185.   Chris Roberts, François Lionet, Archer MacLean, everybody at ID Software and
  186.   Apogee, Sierra On-Line, Lucas Arts and Team 17, for showing me what 
  187.   programming is all about.
  188.  
  189.  
  190. ■ Bikes and programs - What to they have in common ?
  191.  
  192.   ■ Introduction
  193.  
  194.     They cicle, that's what !!! If you don't know what I'm talking about, this
  195.   article is just for you...
  196.     Let's say that you wanted to make a program to write ten times 'Spellcaster'
  197.   on the screen. One aproach would be like this:
  198.  
  199.   Program Test_10;
  200.  
  201.   Begin
  202.        Writeln('Spellcaster');
  203.        Writeln('Spellcaster');
  204.        Writeln('Spellcaster');
  205.        Writeln('Spellcaster');
  206.        Writeln('Spellcaster');
  207.        Writeln('Spellcaster');
  208.        Writeln('Spellcaster');
  209.        Writeln('Spellcaster');
  210.        Writeln('Spellcaster');
  211.        Writeln('Spellcaster');
  212.        Readln;
  213.   End.
  214.  
  215.     But, this aproach has several errors, computationaly speaking. It isn't
  216.   logic and efficent. Imagine I wanted to write it 100 times?! So, someone
  217.   really clever tought up a thing called a cicle. A cicle is something that
  218.   repeats itself for a number of times, or until a condition is met. See the
  219.   last example re-writen:
  220.  
  221.   Program Test_11;
  222.  
  223.   Var A:Word;
  224.  
  225.   Begin
  226.        For A:=1 To 10 Do Writeln('Spellcaster');
  227.        Readln;
  228.   End.
  229.  
  230.     See, how economical it is? It saves time and valuable memory. There are
  231.   three kinds of cicles, each one of them with their advantages and
  232.   disadvantages.
  233.  
  234.   ■ The For cicle
  235.  
  236.     The For cicle is for me the simplest one to use, and it is very usefull,
  237.   in all circumstances. The sintax is:
  238.  
  239.               For variable:=firstvalue To lastvalue Do instruction
  240.  
  241.     What this command does is this:
  242.               1. Assigns firstvalue to the variable
  243.               2. Executes instruction
  244.               3. Adds one to the variable
  245.               4. Returns to 2 if the value in the variable is different from
  246.                  the lastvalue.
  247.  
  248.     You can use the For keyword with the Begin and End keywords, like this:
  249.  
  250.               For variable:=firstvalue To lastvalue Do
  251.               Begin
  252.                    instructions
  253.               End;
  254.  
  255.     In this case, Pascal executes all instruction between the begin and end
  256.   clauses, before incrementing the variable.
  257.     Let's see an example:
  258.     Imagine you wanted to show on the screen the numbers from 1 to 20:
  259.  
  260.   Program Test_12;
  261.  
  262.   Var A:Word;
  263.  
  264.   Begin
  265.        For A:=1 To 20 Do Writeln(A);
  266.        Readln;
  267.   End.
  268.  
  269.     See how simple this is? Now, let's try something similar... Show the
  270.   numbers from -20 to 5...
  271.  
  272.   Program Test_13;
  273.  
  274.   Var A:Word;
  275.  
  276.   Begin
  277.        For A:=-20 To 5 Do Writeln(A);
  278.        Readln;
  279.   End.
  280.  
  281.     This also works...
  282.     Note that the first value must be smaller than the last value, or else
  283.   the cicle won't have effect. If you want to do reverse order, change the
  284.   To keyword to DownTo, like this:
  285.  
  286.   Program Test_14;
  287.  
  288.   Var A:Word;
  289.  
  290.   Begin
  291.        For A:=150 DownTo 130 Do Writeln(A);
  292.        Readln;
  293.   End.
  294.  
  295.     As you may already have guessed, this writes the numbers from 150 to 130.
  296.     Remember that you can use a varible instead of a number, when you specify
  297.   the cicle range:
  298.  
  299.   Program Test_15;
  300.  
  301.   Var A:Word;
  302.       B:Byte;
  303.  
  304.   Begin
  305.        B:=150;
  306.        For A:=B DownTo 130 Do Writeln(A);
  307.        Readln;
  308.   End.
  309.  
  310.     Well, that's it for the For loop...
  311.  
  312.   ■ The Repeat...Until...
  313.  
  314.     Sometimes, you must cicle something until a certain condition is met. There
  315.   are two ways of doing this (there are actually more, but the others are just
  316.   plain stupid).
  317.     The first one is the Repeat...Until keywords. The sintax is as follows:
  318.  
  319.               Repeat
  320.                     instructions
  321.               Until (condition is true)
  322.  
  323.  
  324.     This executes the instructions UNTIL the condition is met...
  325.     For example, imagine you wanted the computer to give you the powers of two,
  326.   until the number is larger than 10000...
  327.  
  328.   Program Test_16;
  329.  
  330.   Var A:Word;
  331.  
  332.   Begin
  333.        A:=1;
  334.        Repeat
  335.              A:=A*2;
  336.              Writeln(A);
  337.        Until A>10000;
  338.        Readln;
  339.   End.
  340.  
  341.     Note that you don't have to use the Begin and End keywords in the Repeat
  342.   loop (this is why I like the Repeat very much and use almost everytime).
  343.     Also note that if the initial number was 10001, the computer would print
  344.   the number 20002 on the screen, a number that is larger than 10000. Why is
  345.   that ?! Before you start throwing away your copy of Pascal out of anger,
  346.   notice that the checking is done AFTER the first execution. If you want to
  347.   test before, you must use the...
  348.  
  349.   ■ While loop
  350.  
  351.     The only differences between the Repeat...Until... loop and the While loop
  352.   resides just in two things:
  353.  
  354.           First: The checking is performed in the start of the loop, in case of
  355.                  the While loop.
  356.           Second: To execute multiple instructions in the While loop, you must
  357.                   use the Begin and End clauses.
  358.  
  359.  
  360.     Check the above program re-writen to use the While loop:
  361.  
  362.   Program Test_17;
  363.  
  364.   Var A:Word;
  365.  
  366.   Begin
  367.        A:=1;
  368.        While A<10000 Do
  369.        Begin
  370.             A:=A*2;
  371.             Writeln(A);
  372.        End;
  373.        Readln;
  374.   End.
  375.  
  376.     Notice the 'While A<10000 Do' line... You probably noted that it very
  377.   different from the Repeat. The reason is that they have a different "meaning".
  378.   The sintax for the While loop is:
  379.  
  380.              While (condition is true) Do instruction
  381.  
  382.                                  or
  383.  
  384.              While (condition is true) Do
  385.              Begin
  386.                   instructions
  387.              End;
  388.  
  389.     This executes the instruction(s) WHILE the condition is met... Compare it
  390.   with the Repeat...Until... loop...
  391.  
  392.     There isn't any rules of usage for the For, While and Repeat loops... As in
  393.   everything in coding (=programming), you must try to learn. Each one of them
  394.   has it's advantages and disadvantages.
  395.  
  396.  
  397. ■ Graphics, part III : Lines and Circles
  398.  
  399.     This issues's graphics tutorial is about lines and circles, a very important
  400.   part of many programms. These are one of the tougher subjects to teach (for me,
  401.   at least), and it may be confusing for starters; but don't despair... Try to
  402.   work it out.
  403.  
  404.   ■ Lines
  405.  
  406.     This is a tricky subject to talk about... There are so many ways to do a
  407.   line, that I don't know were to start. I will start to talk about a general
  408.   algorythm.
  409.     Let's say you want to draw a line from (x1,y1) to (x2,y2), like this:
  410.  
  411.           (x1,y1)
  412.                  oooooooooo
  413.                            oooooooooo
  414.                                      ooooooooooo
  415.                                                 (x2,y2)
  416.  
  417.     Now, you must find out the length of the line:
  418.  
  419.                   deltaX := Abs (x2-x1);
  420.                   deltaY := Abs (y2-y1);
  421.  
  422.     If one of these variables (deltax or deltay) is 0, the line is horizontal
  423.   or vertical. In that case, the program should branch to a specific part,
  424.   because the division by zero error.
  425.     Know, you must find out the slope of the line... You do that like this:
  426.  
  427.                   Xslope := deltaX / deltaY;
  428.                   Yslope := deltaY / deltaX;
  429.  
  430.     Looks familiar ?... This is standart trigonometry (trig for short). But, if
  431.   you remember trig, you will now now that there are two line equations:
  432.  
  433.                   X := Xslope * Y;
  434.                   Y := Yslope * X;
  435.  
  436.     So, which one to use ?... If you use the wrong one, you'll end up with
  437.   something like this:
  438.  
  439.             o
  440.                   o
  441.                         o
  442.  
  443.   instead of this:
  444.  
  445.             oooooo
  446.                   oooooo
  447.                         oooooo
  448.  
  449.  
  450.     Well, you must find out which one to use. Picture this:
  451.  
  452.                               o\xx|xx/o
  453.                               oo\x|x/oo
  454.                               ooo\|/ooo
  455.                               ----+----
  456.                               ooo/|\ooo
  457.                               oo/x|x\oo
  458.                               o/xx|xx\o
  459.  
  460.     If the slope angle is in the 'o's area, then you must use the first
  461.   equation. If it is in the 'x's area, use the second. In the middle position,
  462.   use either.
  463.     When you find out what line to use, you just have to loop the right hand
  464.   variable, and calculate the left side one from it.
  465.     Well, we almost everything we need, except for a function that returns the
  466.   signal of a number. The function (Sgn) returns 1 if the number is positive, -1
  467.   if the number is negative or 0 if the number is zero.
  468.  
  469.     Function Sgn(A:Real):Integer;
  470.     Begin
  471.          If A<0 then Sgn:=-1;
  472.          If A=0 then Sgn:=0;
  473.          If A>0 then Sgn:=+1;
  474.     End;
  475.  
  476.     Now, here's the line procedure...
  477.  
  478.     Procedure Line(X1,Y1,X2,Y2,Col:Integer);
  479.     Var Deltax,S,Deltay,Dx1,Dy1,Dx2,Dy2,S1,S2:Real;
  480.         I:Integer;
  481.     Begin
  482.          Deltax:=X2-X1;
  483.          Deltay:=Y2-Y1;
  484.          Dx1:=Sgn(Deltax);
  485.          Dy1:=Sgn(Deltay);
  486.          Dx2:=Sgn(Deltax);
  487.          Dy2:= 0;
  488.          S1:=Abs(Deltax);
  489.          S2:=Abs(Deltay);
  490.          If Not (S1>S2) Then
  491.          Begin
  492.               Dx2:=0;
  493.               Dy2:=Sgn(Deltay);
  494.               S1:=Abs(Deltay);
  495.               S2:=Abs(Deltax);
  496.          End;
  497.          S:=Int(S1/2);
  498.          For I:=0 To Round(S1) Do
  499.          Begin
  500.               PutPixel(X1,Y1,Col);
  501.               S:=S+S2;
  502.               If Not (S<S1) Then
  503.               Begin
  504.                    S:=S-S1;
  505.                    X1:=X1+Round(Dx1);
  506.                    Y1:=Y1+Round(Dy1);
  507.               End
  508.               Else
  509.               Begin
  510.                    X1:=X1+Round(dx2);
  511.                    Y1:=Y1+Round(Dy2);
  512.               End;
  513.          End;
  514.     End;
  515.  
  516.     I think this routine is pretty trivial, if you did understand the theory
  517.   behind it. If you didn't understood the theory, go and get your 9th grade
  518.   math's book, and read the trig part... It is vital to line compreension, and
  519.   to the following part:
  520.  
  521.   ■ Circles
  522.  
  523.     Circles are just a matter of knowing the theorem of an old friend of ours:
  524.   Pythagoras... Yes, that ancient greek (geek ?!) once told his grandsons that
  525.   the square of the hipotenusa of a triangle equals the sum of the squares of
  526.   the other two sides. Mathematically:
  527.  
  528.                                 h²=c1²+c1²
  529.  
  530.     This is very important, because it enables us to draw a circle on the
  531.   screen, using also the trigonometrical circle:
  532.  
  533.                               90
  534.                              ████
  535.                             ██  ██
  536.                            ██    ██     <--- This is a trigonometrical
  537.                         180██    ██ 0        circle (altough it doesn't look
  538.                             ██  ██           like one)...
  539.                              ████
  540.                              270
  541.  
  542.     This scheme is great, but it is wrong in Pascal, because:
  543.         1) Pascal use radians, instead of degrees. So the circle goes from
  544.            0 to 2π, instead of 0° to 360°.
  545.         2) Pascal uses reverse angling (is this correct ?).
  546.  
  547.                              270
  548.                              ████
  549.                             ██  ██
  550.                            ██    ██     <--- This is a trigonometrical
  551.                         180██    ██ 0        circle (altough it doesn't look
  552.                             ██  ██           like one)...
  553.                              ████
  554.                               90
  555.  
  556.     So, do know the X and Y coordinates of all points in the circle, you just
  557.   have to loop around the angles and use the following formula:
  558.  
  559.                         X:=R*Sin(Angle);
  560.                         Y:=R*Cos(Angle); where R is the radius of the circle.
  561.  
  562.     The final procedure is something like this:
  563.  
  564.     Procedure Circle(X,Y,R:Integer;Col:Byte);
  565.     Var Px,Py:Integer;
  566.         Deg:Real;
  567.     Begin
  568.          Deg:=0;
  569.          Repeat
  570.                Px:=R*Sin(Deg)+X;
  571.                Py:=R*Cos(Deg)+Y;
  572.                PutPixel(Px,Py,Col);
  573.                Deg:=Deg+0.005;
  574.          Until Deg>2*PI;
  575.     End;
  576.  
  577.     I think this is a simple procedure. As for the theory, this is 9th grade
  578.   math. If you haven't reach it yet, or you don't understand shit about maths,
  579.   write to me and I'll teach you... If enough of people write to me, I may even
  580.   include a complete explanation on trigonometry in a near issue.
  581.  
  582.     There is room for expansion in this routines. For example, try to use
  583.   diferent radius values for the calculation of the Px and Py variables, or try
  584.   adding a different value to Deg, for example, 0.01. Experiment.
  585.     With this issue of 'The Mag', you probably noticed a Pascal source code. It
  586.   is the source code of a couple of effects. One you might recognize from the
  587.   Color Blind demo I gave away in last issue. It is probably slower than the one
  588.   in Color Blind, because the line routine I use in the demo is almost 100%
  589.   assembler. The other effect is very SLOWWWW... I will teach how to speed it
  590.   up in next issue. It is due to sines and cosines calculation.
  591.  
  592.     If you like to experiment, try finding a book or a doc on the Bressenhams
  593.   algorythms. These algorythms are a lot faster than the routines I'm giving
  594.   you, and are based on the simmetry of the objects. I don't have any docs on
  595.   it, but I can do an explanation of them in a future issue, if you ask me to.
  596.  
  597.  
  598.  
  599. ■ Hints and Tips
  600.  
  601.     Welcome to the new regular... It is a tricks part, where I teach some
  602.   short tricks about programming. Every tip has a number of stars on the
  603.   title. This is the level of it:
  604.  
  605.               *   - This is for begginners
  606.               **  - Medium
  607.               *** - Advanced (there will not be a lot of these, because I'm not
  608.                               that good...)
  609.  
  610.  
  611.     - Division by zero (*)
  612.  
  613.       If you executed the Maths program I gave you in issue 3, and you
  614.       selected 0 as the second number in the division, you would get an error
  615.       message (Division by Zero). This error is caused by (as you don't know)
  616.       by diving something by zero, because in Pascal (as in real life),
  617.       division by zero is impossible. So, you should always check if the
  618.       division's second term is non-zero.
  619.  
  620.     - Super fast multiplication (**)
  621.  
  622.       If I said that there was a way to multiply by a two (or any power of two)
  623.       that was more than twenty times faster, you'll probably put me in a
  624.       sanitarium. Well, as the matter of fact, there is.
  625.       If you translate a decimal number to binary and you shift the bits to the
  626.       left, and you convert again to decimal, you'll have a multiplication by
  627.       two, but a lot faster than standart multiplication. Schematically:
  628.  
  629.                50 = 00110010 ; Then, you shift left...
  630.  
  631.                     01100100 = 100 ; If you shift again to the left...
  632.  
  633.                     11001000 = 200 ; So, by shifting two bits to the left, you
  634.                                      multiplied 50 by 4 (2²)
  635.  
  636.       As you may have figured out already, you can do the opposite (shift
  637.       right) to divide by two (again ultra-fast).
  638.       The ideia is this:
  639.  
  640.                     B:=A*2        equals        B:=A shl 1
  641.                     B:=A*4        equals        B:=A shl 2
  642.                     B:=A*8        equals        B:=A shl 3
  643.                     B:=A*16       equals        B:=A shl 4
  644.  
  645.       And:
  646.  
  647.                     B:=A div 2    equals        B:=A shr 1
  648.                     B:=A div 4    equals        B:=A shr 2
  649.                     B:=A div 8    equals        B:=A shr 3
  650.                     B:=A div 16   equals        B:=A shr 4
  651.  
  652.       So, you have an ultra-fast way of doing mults (short for multiplication)
  653.       and divs (short for divisions) by powers of two.
  654.  
  655.  
  656. ■ Points of View
  657.  
  658.     This week's point of view is... I don't know what. I don't really don't
  659.   know what to talk about, so I'll talk about censorship. A week ago, I tried
  660.   to put this mag in a BBS, that shall remain nameless. After I've downloaded
  661.   it, I received a message from the Sysop, saying that he didn't wanted crap
  662.   like this in his BBS. Just because I said shit... And because I made fun of
  663.   Atari and Bill Gates in the Adventures of Spellcaster. If this isn't
  664.   censorship, I don't know what is... People should be free, not manipulated
  665.   by a bunch of burocrats and new-age folks that think that shit like this isn't
  666.   intended for this pure world of ours. Our world is a fun place... It's the
  667.   only place in the Universe were people say shit and other things like that,
  668.   and make fun of others when talking, but when they write it, they say it is
  669.   filthy and degradating for the human race. I can understand their concern,
  670.   but people must realize some stuff:
  671.   - When somebody does something for fun, that person MUST have some fun doing
  672.     it, and depriving someone (namelly me) of writing things that he likes, is
  673.     wrong.
  674.   - A person that can handle a modem to download my mag, or that can operate
  675.     computers has enough age to read something like it
  676.   - Censorship is a crime (we have freedom of speech... At least here in
  677.     Portugal).
  678.   Fortunatly this is a free country, and I can say what I want to... So I say,
  679.   quoting one of my favorite bands (Iron Maiden):
  680.  
  681.                              I'm not a number... I'm a free man
  682.  
  683.  
  684.     Next issue, I'm gonna write the fourth part of the Graphics tut, about
  685.   pre-generated arrays and virtual screens. I'm thinking of also including
  686.   another tutorial on assembler, but I'm not sure I will...
  687.  
  688.  
  689.  
  690. ■ The adventures of Spellcaster, the rebel programmer of the year 2018.
  691.  
  692.   Episode 4 - Brotherhood of the Rebel Programmers
  693.  
  694.     My scream still echoed in the old powerplant, a relic from the year 1998.
  695.   Me and my new friend were lying on the ground, grasping to get air after our
  696.   long run. The sirens of the Atari Penetenciary were silent now, and the only
  697.   sound heard was the sound of a jetcopter flying overhead. I sat down and
  698.   looked at the blond man.
  699.   - Thanks... - I said, smilling at my saviour.
  700.   - You're welcome... You've also saved my life, by enabling me to get out of
  701.     that madhouse.
  702.   A long silent period followed, as we studied each other, trying to figure
  703.   out if we could trust one another.
  704.   - My name's Diogo, also known by SpellCaster... - I said, streching out my
  705.     hand towards the man.
  706.   - I'm Gundsen, Karl Gundsen. In the Universenet I was known by the codename
  707.     DeathRipper.
  708.   The ambient of the room lightened up, and the conversation continued in a
  709.   friendly manner:
  710.   - So, what were in for ? - asked Gundsen
  711.   - I was sentenced for 30 years, for not having Windows 2018.
  712.   - You're a programmer ?! - Gundsen opened up his eyes, apparently surprised.
  713.   - Yes... For my sins... - I said sadly, thinking of my old computer. - So,
  714.     what's your story ?
  715.   - I was going to be executed tomorrow...
  716.   - WHAT ?! - I yelled, suddently frightned.
  717.   - Relax... I didn't killed anyone.
  718.   - So, what did you do ? - I asked, still scared.
  719.   - I tried to penetrate the Gate...
  720.   - The Gate ? - I asked, because I didn't knew what the Gate was.
  721.   - Yes... The software defense sistem of Comptel.
  722.   - You're a hacker. - I said, honnored to meet one of them. the hackers were
  723.     a type of programmers that were tought extinct in the end of the 20th
  724.     century.
  725.   - Ye... Probably the last one. - he said proud, sitting up straight.
  726.   - But why did you tried to break into Comptel's system.
  727.   - I want to find out a way to know and destroy the NeuroFrame, Comptel's main
  728.     system. If I succeed, Comptel's reign of terror will reach an abrupt end.
  729.   I looked at him, trying to figure out the mixed emotions in Gundsen eyes.
  730.   - You said 'I want'... After the first failure, you still want to get into
  731.     Comptel's system ?
  732.   - Definatly... I made one mistake in the final defense, and it cost me my
  733.     freedom, and almost my life.
  734.   I thought about it... It made sense. Comptel needed to be stopped, from
  735.   preventing it to arrest and kill innocent people like me and DeathRipper.
  736.   - Do you need help ?... - I asked, standing up and looking directly into him.
  737.   He smilled and stood up. He streched out his hand and we shook hands.
  738.   - Sure, SpellCaster... But are you sure you want to try... If we are caught,
  739.   we can die... And it will not be easy.
  740.   - Hey, all my life I wanted to be a hacker... And besides, it is better to die
  741.   with honor, than to be a fugitive the rest of my life.
  742.   - Ok... Thanks... - he said, smilling.
  743.   - All we need now is a name for our movement...
  744.   We thought for a minute or so.
  745.   - How about "The Bill Gates Hatters Club"... - I said.
  746.   - I think it sucks...
  747.   - Me too...
  748.   We thought a bit more.
  749.   - And "Comptel's Destruction Group"... - he said.
  750.   - Please... That almost made me puke.
  751.   - Ok, ok...
  752.   After two hours of thinking, we came to a conclusion:
  753.   The Brotherhood of the Rebel Programmer was born !...
  754.  
  755.  
  756.                                          See you in the next issue
  757.                                         Diogo "SpellCaster" Andrade